home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-05-15 | 1.1 KB | 46 lines | [TEXT/CWIE] |
- // rename_patch.c
- // 15May1997 e
-
- // MSL 2.1.1 doesn't rename directories; here's a fix...
-
- #include <stdio.h>
- #include <file_io.h>
- #include "os_mac_str.h" // c_to_p()
-
- static OSErr e_path2fss( const char *filename, FSSpec *fss )
- {
- Str255 buf;
- long cur_dir;
- short cur_vol;
-
- c_to_p( (char *)filename, buf );
- HGetVol( NULL, &cur_vol, &cur_dir );
- return FSMakeFSSpec( cur_vol, cur_dir, buf, fss );
- }
-
- #define io_result(ioResult) ((ioResult == noErr) ? (int) __no_io_error : (int) __io_error)
-
- int __rename_file(const char * old_name, const char * new_name)
- {
- FSSpec old_spec, new_spec;
- OSErr ioResult;
- HParamBlockRec pb;
-
- if ((ioResult = e_path2fss(old_name, &old_spec)) != 0 )
- return(__io_error);
-
- if ((ioResult = e_path2fss(new_name, &new_spec)) != fnfErr)
- return(__io_error);
-
- if (old_spec.vRefNum != new_spec.vRefNum || old_spec.parID != new_spec.parID)
- return(__io_error);
-
- pb.ioParam.ioNamePtr = old_spec.name;
- pb.ioParam.ioVRefNum = old_spec.vRefNum;
- pb.fileParam.ioFVersNum = 0;
- pb.ioParam.ioMisc = (Ptr) new_spec.name;
- pb.fileParam.ioDirID = old_spec.parID;
-
- return(io_result(PBHRenameSync(&pb)));
- }
-